<template>
    <div>
        <table>
            <tr>
                <td>编号</td>
                <td>
                    <input type="text" v-model="data.bh">
                </td>
            </tr>
       
            <tr>
                <td>名称</td>
                <td>
                    <input type="file" @change="tpp">
                    <img :src="'https://localhost:7219/'+data.mc" style="width: 100px; height: 100px;" >
                </td>
            </tr>
            <tr>
                <td>楼层</td>
                <td>
                    <select v-model="data.louc">
                        <option value="3层">3层</option>
                        <option value="4层">4层</option>
                        <option value="5层">5层</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <input type="button" value="添加" @click="dl">
                </td>
            </tr>
        </table>

    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref } from 'vue';

const data=ref({
    "id": 0,
  "bh": "hb2323424",
  "mc": "黄金甲",
  "louc": "3层"
})
  23
const dl=()=>{
    axios.post("https://localhost:7219/api/we/add",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功")
            location.href="/xs"
        }else{
            alert("添加失败")
        }
    })
}
const tpp=(a:any)=>{
    var f = a.target.files[0];
    if(f.size>2*1024*1024){
        alert("上传文件要小于2mb")
        return
    }
    var fd = new FormData();
    fd.append("file",f)
    axios.post("https://localhost:7219/api/tp",fd).then(res=>{
        data.value.mc=res.data;
    })

}

</script>

<style scoped>

</style>